import pygame
from nSprit import *

pygame.init()
screen = pygame.display.set_mode((480, 700))

back_img = pygame.image.load("./images/background.png")
screen.blit(back_img, (0, 0))
# pygame.display.update()

hero_img = pygame.image.load("./images/me1.png")
hero_rect = pygame.Rect(200, 300, 102, 126)
screen.blit(hero_img, (200, 500))
pygame.display.update()

colok = pygame.time.Clock()

enemy = GameSprite("./images/enemy1.png")
enemy1 = GameSprite("./images/enemy1.png", 2)
enemy_group = pygame.sprite.Group(enemy, enemy1)


while True:
    colok.tick(60)
    hero_rect.y -= 1
    screen.blit(back_img, (0, 0))
    screen.blit(hero_img, hero_rect)
    enemy_group.update()
    enemy_group.draw(screen)
    pygame.display.update()

    if hero_rect.y <= -126:
        hero_rect.y = 700
    

    # pygame.display.update()
    for event in pygame.event.get():
        # 判断事件类型是否是退出事件
        if event.type == pygame.QUIT:
            print("游戏退出...")

            # quit 卸载所有的模块
            pygame.quit()

            # exit() 直接终止当前正在执行的程序
            exit()
pygame.quit()


